package com.qigao.mall.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.qigao.mall.api.ItemCatService;
import com.qigao.mall.api.ItemService;
import com.qigao.mall.api.ShopInfoService;
import com.qigao.mall.commons.dto.*;
import com.qigao.mall.commons.enums.*;
import com.qigao.mall.commons.exceptions.BusinessException;
import com.qigao.mall.commons.utils.IDUtils;
import com.qigao.mall.jdbc.mapper.TbItemDetailMapper;
import com.qigao.mall.jdbc.mapper.TbItemMapper;
import com.qigao.mall.jdbc.mapper.TbItemPicMapper;
import com.qigao.mall.jdbc.mapper.TbItemSkuMapper;
import com.qigao.mall.jdbc.model.TbItem;
import com.qigao.mall.jdbc.model.TbItemDetail;
import com.qigao.mall.jdbc.model.TbItemPic;
import com.qigao.mall.jdbc.model.TbItemSku;
import org.apache.commons.lang3.RandomUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.support.DefaultTransactionDefinition;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @author luiz
 * @Title: com.qigao.mall.service
 * @ProjectName three-mall
 * @date 2019-11-2019/11/1 14:11
 * @Description: 商品服务具体实现类
 */
@Service
public class ItemServiceImpl implements ItemService {
    private static final Logger logger= LoggerFactory.getLogger(ItemServiceImpl.class);
    @Resource
    TbItemMapper tbItemMapper;
    @Resource
    TbItemDetailMapper tbItemDetailMapper;
    @Resource
    TbItemSkuMapper tbItemSkuMapper;
    @Value("${qigao.pay.domain}")
    private String payDomain;
    @Resource
    ItemCatService itemCatService;
    @Resource
    private TbItemPicMapper tbItemPicMapper;
    @Resource
    private ShopInfoService shopInfoService;
    @Autowired
    private PlatformTransactionManager txManager;

    @Override
    public Page<ItemResultDto> search(ItemQueryPageDto itemQueryPageDto) {
        PageHelper.startPage(itemQueryPageDto.getPageNum(),itemQueryPageDto.getPageSize());
        Page<TbItem> tbItemPage = (Page<TbItem>)tbItemMapper.selectByKeyWords(itemQueryPageDto);
        Page<ItemResultDto> itemResultDtoPage = new Page<ItemResultDto>();
        BeanUtils.copyProperties(tbItemPage,itemResultDtoPage);
       if(tbItemPage.getResult()!=null && tbItemPage.getResult().size()>=1){
           for(TbItem tbItem:tbItemPage.getResult()){
               ItemResultDto itemResultDto =convertToDto(tbItem);
               itemResultDtoPage.add(itemResultDto);
           }
       }
        return itemResultDtoPage;
    }


    @Override
    public List<ItemResultDto> showItemByCatNo(String catNo, String status) {
        List<TbItem> tbItems =tbItemMapper.selectByCatNo(catNo,status);
        List<ItemResultDto> itemResultDtos =new ArrayList<>();
        if(tbItems!=null && tbItems.size()>=1){
            for(TbItem tbItem:tbItems){
                ItemResultDto itemResultDto =convertToDto(tbItem);
                itemResultDtos.add(itemResultDto);
            }
        }
        return itemResultDtos;
    }

    @Override
    public void addGoods(ItemUpdateDto itemCreateDto) {
        ShopInfoDto shopInfoDto =shopInfoService.findByShopNo(itemCreateDto.getShopNo());
        if(shopInfoDto ==null){
            throw new BusinessException(ResultCode.SHOP_NOT_EXITS);
        }
        TransactionStatus status = txManager.getTransaction(new DefaultTransactionDefinition());
        try{
            TbItem tbItem=new TbItem();
            BeanUtils.copyProperties(itemCreateDto,tbItem);
            tbItem.setMerNo(shopInfoDto.getMerNo());
            String itemNo= IDUtils.genIdStr(IdTypeEnum.GOODS.getCode());
            tbItem.setItemNo(itemNo);
            tbItem.setPicUrl(itemCreateDto.getPicUrl());
            tbItem.setNarrowPicUrl(itemCreateDto.getNarrowPicUrl());
            if (itemCreateDto.getStockNum() != null){
                tbItem.setStockNum(new BigDecimal(itemCreateDto.getStockNum()));
                tbItem.setStockType(StockTypeEnum.STCOK_LIMIT.getCode());
            }
            if(itemCreateDto.getPrice()!=null)
                tbItem.setPrice(new BigDecimal(itemCreateDto.getPrice()));
            if(itemCreateDto.getCostPrice()!=null)
                tbItem.setCost(new BigDecimal(itemCreateDto.getCostPrice()));
            tbItem.setCreateNo(itemCreateDto.getUserNo());
            tbItem.setCreateTime(new Date());
            tbItem.setModiNo(itemCreateDto.getUserNo());
            tbItem.setModiTime(new Date());
            List<TbItemPic> itemPics=new ArrayList<>();
            for(ItemPicDto itemPicDto:itemCreateDto.getItemPicDtos()){
                TbItemPic tbItemPic=new TbItemPic();
                tbItemPic.setItemNo(itemNo);
                tbItemPic.setPicLocation(itemPicDto.getPicLocation());
                tbItemPic.setPicUrl(itemPicDto.getPicNo());
                tbItemPic.setNarrowPicUrl(itemPicDto.getNarrowPicNo());
                tbItemPic.setPicTitle(itemPicDto.getPicTitle());
                tbItemPic.setIsMain(itemPicDto.getIsMain());
                tbItemPic.setShopNo(itemCreateDto.getShopNo());
                tbItemPic.setMerNo(shopInfoDto.getMerNo());
                tbItemPic.setCreateNo(itemCreateDto.getUserNo());
                tbItemPic.setCreateTime(new Date());
                tbItemPic.setVersion(1);
                tbItemPic.setModiNo(itemCreateDto.getUserNo());
                tbItemPic.setModiTime(new Date());
                itemPics.add(tbItemPic);
            }
            if(StringUtils.isNotEmpty(itemCreateDto.getItemDesc())) {
                TbItemDetail tbItemDetail = new TbItemDetail();
                tbItemDetail.setItemNo(itemNo);
                tbItemDetail.setMerNo(shopInfoDto.getMerNo());
                tbItemDetail.setShopNo(itemCreateDto.getShopNo());
                tbItemDetail.setDescription(itemCreateDto.getItemDesc());
                tbItemDetail.setCreateNo(itemCreateDto.getUserNo());
                tbItemDetail.setCreateTime(new Date());
                tbItemDetail.setVersion(1);
                tbItemDetail.setModiNo(itemCreateDto.getUserNo());
                tbItemDetail.setModiTime(new Date());
                tbItemDetailMapper.insertSelective(tbItemDetail);
            }
            List<TbItemSku> tbItemSkus=new ArrayList();
            List<ItemSkuDto> itemSkuDtos=itemCreateDto.getItemSkuDtos();
            if(itemSkuDtos!=null && itemSkuDtos.size()>=1){
                for(ItemSkuDto itemSkuDto:itemSkuDtos){
                    TbItemSku tbItemSku=new TbItemSku();
                    BeanUtils.copyProperties(itemSkuDto,tbItemSku);
                    tbItemSku.setScorePercent(new BigDecimal(itemSkuDto.getScorePercent()));
                    tbItemSku.setItemNo(itemNo);
                    tbItemSku.setStockType(StockTypeEnum.STOCK_FREE.getCode());
                    if(itemSkuDto.getStockNum()!=null){
                        tbItemSku.setStockNum(new BigDecimal(itemSkuDto.getStockNum()));
                        tbItemSku.setStockType(StockTypeEnum.STCOK_LIMIT.getCode());
                    }
                    String costPrice=StringUtils.isEmpty(itemSkuDto.getCostPrice())?"0.00":itemSkuDto.getCostPrice();
                    tbItemSku.setCost(new BigDecimal(costPrice));
                    String salePrice=StringUtils.isEmpty(itemSkuDto.getSalePrice())?"0.00":itemSkuDto.getSalePrice();
                    tbItemSku.setSalePrice(new BigDecimal(salePrice));
                    String price=StringUtils.isEmpty(itemSkuDto.getPrice())?"0.00":itemSkuDto.getPrice();
                    tbItemSku.setPrice(new BigDecimal(price));
                    String returnRate=StringUtils.isEmpty(itemSkuDto.getReturnRate())?"0.00":itemSkuDto.getReturnRate();
                    tbItemSku.setReturnRate(new BigDecimal(returnRate));
                    String stockNo=IDUtils.genIdStr(IdTypeEnum.STOCK);
                    tbItemSku.setPicUrl(itemSkuDto.getPicNo());
                    tbItemSku.setNarrowPicUrl(itemSkuDto.getNarrowPicNo());
                    tbItemSku.setShopNo(itemCreateDto.getShopNo());
                    tbItemSku.setMerNo(tbItem.getMerNo());
                    tbItemSku.setStockNo(stockNo);
                    tbItemSku.setVersion(1);
                    tbItemSku.setCreateNo(itemCreateDto.getUserNo());
                    tbItemSku.setCreateTime(new Date());
                    tbItemSku.setModiNo(itemCreateDto.getUserNo());
                    tbItemSku.setModiTime(new Date());
                    tbItemSkus.add(tbItemSku);
                }
            }
            tbItemPicMapper.insertBatch(itemPics);
            tbItemMapper.insertSelective(tbItem);
            tbItemSkuMapper.insertBatch(tbItemSkus);
            txManager.commit(status);
            logger.info("创建商品成功!{}",itemNo);
        }catch (Exception e){
            txManager.rollback(status);
            logger.error("创建商品发生异常:{}",e);
        }
    }

    @Override
    public void modiGoods(ItemUpdateDto itemUpdateDto) {
        ShopInfoDto shopInfoDto =shopInfoService.findByShopNo(itemUpdateDto.getShopNo());
        if(shopInfoDto ==null){
            throw new BusinessException(ResultCode.SHOP_NOT_EXITS);
        }
        TransactionStatus status = txManager.getTransaction(new DefaultTransactionDefinition());
        try {
            TbItem tbItem = new TbItem();
            BeanUtils.copyProperties(itemUpdateDto, tbItem);
            String itemNo = itemUpdateDto.getItemNo();
            tbItem.setMerNo(shopInfoDto.getMerNo());
            tbItem.setPicUrl(itemUpdateDto.getPicUrl());
            tbItem.setNarrowPicUrl(itemUpdateDto.getNarrowPicUrl());
            tbItem.setStockType(StockTypeEnum.STOCK_FREE.getCode());
            if (itemUpdateDto.getStockNum() != null){
                tbItem.setStockNum(new BigDecimal(itemUpdateDto.getStockNum()));
                tbItem.setStockType(StockTypeEnum.STCOK_LIMIT.getCode());
            }
            if (itemUpdateDto.getPrice() != null)
                tbItem.setPrice(new BigDecimal(itemUpdateDto.getPrice()));
            tbItem.setModiNo(itemUpdateDto.getUserNo());
            tbItem.setModiTime(new Date());
            tbItemMapper.updateByItemNo(tbItem);
            if(StringUtils.isNotEmpty(itemUpdateDto.getItemDesc())){
                TbItemDetail tbItemDetail=new TbItemDetail();
                tbItemDetail.setItemNo(itemNo);
                tbItemDetail.setMerNo(shopInfoDto.getMerNo());
                tbItemDetail.setShopNo(itemUpdateDto.getShopNo());
                tbItemDetail.setDescription(itemUpdateDto.getItemDesc());
                tbItemDetail.setCreateNo(itemUpdateDto.getUserNo());
                tbItemDetail.setCreateTime(new Date());
                tbItemDetail.setModiNo(itemUpdateDto.getUserNo());
                tbItemDetail.setModiTime(new Date());
                tbItemDetailMapper.updateByItemNo(tbItemDetail);
            }
            List<TbItemPic> itemUpdatePics=new ArrayList<>();
            List<TbItemPic> itemCreatePics=new ArrayList<>();
            for(ItemPicDto itemPicDto:itemUpdateDto.getItemPicDtos()){
                TbItemPic tbItemPic=new TbItemPic();
                BeanUtils.copyProperties(itemPicDto,tbItemPic);
                tbItemPic.setItemNo(itemNo);
                tbItemPic.setPicUrl(itemPicDto.getPicNo());
                tbItemPic.setNarrowPicUrl(itemPicDto.getNarrowPicNo());
                tbItemPic.setShopNo(itemUpdateDto.getShopNo());
                tbItemPic.setMerNo(shopInfoDto.getMerNo());
                if(itemPicDto.getId()!=null){
                    tbItemPic.setModiNo(itemUpdateDto.getUserNo());
                    tbItemPic.setModiTime(new Date());
                    itemUpdatePics.add(tbItemPic);
                }else {
                    tbItemPic.setCreateNo(itemUpdateDto.getUserNo());
                    tbItemPic.setCreateTime(new Date());
                    tbItemPic.setModiNo(itemUpdateDto.getUserNo());
                    tbItemPic.setModiTime(new Date());
                    itemCreatePics.add(tbItemPic);
                }
            }
            if(!CollectionUtils.isEmpty(itemUpdatePics)){
                tbItemPicMapper.updateBatch(itemUpdatePics);
                tbItemPicMapper.deleteNotInIds(itemNo,itemUpdatePics);
            }
            if(!CollectionUtils.isEmpty(itemCreatePics)){
                tbItemPicMapper.insertBatch(itemCreatePics);
            }
            List<ItemSkuDto> itemSkuDtos = itemUpdateDto.getItemSkuDtos();
            if (itemSkuDtos != null && itemSkuDtos.size() >= 1) {
                List<TbItemSku> tbItemSkus = new ArrayList();
                List<TbItemSku> tbItemUpdateSkus = new ArrayList();
                for (ItemSkuDto itemSkuDto : itemSkuDtos) {
                    TbItemSku tbItemSku = new TbItemSku();
                    BeanUtils.copyProperties(itemSkuDto, tbItemSku);
                    tbItemSku.setScorePercent(new BigDecimal(itemSkuDto.getScorePercent()));
                    tbItemSku.setStockType(StockTypeEnum.STOCK_FREE.getCode());
                    tbItemSku.setPicUrl(itemSkuDto.getPicNo());
                    tbItemSku.setNarrowPicUrl(itemSkuDto.getNarrowPicNo());
                    if (itemSkuDto.getStockNum() != null){
                        tbItemSku.setStockNum(new BigDecimal(itemSkuDto.getStockNum()));
                        tbItemSku.setStockType(StockTypeEnum.STCOK_LIMIT.getCode());
                    }
                    String costPrice=StringUtils.isEmpty(itemSkuDto.getCostPrice())?"0.00":itemSkuDto.getCostPrice();
                    tbItemSku.setCost(new BigDecimal(costPrice));
                    String salePrice=StringUtils.isEmpty(itemSkuDto.getSalePrice())?"0.00":itemSkuDto.getSalePrice();
                    tbItemSku.setSalePrice(new BigDecimal(salePrice));
                    String price=StringUtils.isEmpty(itemSkuDto.getPrice())?"0.00":itemSkuDto.getPrice();
                    tbItemSku.setPrice(new BigDecimal(price));
                    String returnRate=StringUtils.isEmpty(itemSkuDto.getReturnRate())?"0.00":itemSkuDto.getReturnRate();
                    tbItemSku.setReturnRate(new BigDecimal(returnRate));
                    tbItemSku.setItemNo(itemNo);
                    tbItemSku.setShopNo(itemUpdateDto.getShopNo());
                    tbItemSku.setMerNo(tbItem.getMerNo());
                    tbItemSku.setModiNo(itemUpdateDto.getUserNo());
                    tbItemSku.setModiTime(new Date());
                    if(StringUtils.isEmpty(itemSkuDto.getStockNo())){
                        tbItemSku.setVersion(1);
                        tbItemSku.setCreateNo(itemUpdateDto.getUserNo());
                        tbItemSku.setCreateTime(new Date());
                        String stockNo = IDUtils.genIdStr(IdTypeEnum.STOCK);
                        tbItemSku.setStockNo(stockNo);
                        tbItemSkus.add(tbItemSku);
                    }else {
                        tbItemUpdateSkus.add(tbItemSku);
                    }
                }
                if(!CollectionUtils.isEmpty(tbItemUpdateSkus)){
                    tbItemSkuMapper.updateBatch(tbItemUpdateSkus);
                    tbItemSkuMapper.disableNotInStockNos(itemNo,tbItemUpdateSkus);
                }
                if(!CollectionUtils.isEmpty(tbItemSkus)){
                    tbItemSkuMapper.insertBatch(tbItemSkus);
                }
            }
            txManager.commit(status);
            logger.info("修改商品成功!{}",itemNo);
        }catch (Exception e){
            txManager.rollback(status);
            logger.error("修改商品发生异常:{}",e);
        }
    }

    /***
     * 随机展示四个商品
     * @return
     * @param shopNo
     */
    @Override
    public List<ItemResultDto> randomItem(String shopNo) {
        int showNum=4;
        int totalNum=tbItemMapper.countTotal(shopNo);
        if(totalNum==0){
            logger.info("商品尚未发布...");
            return null;
        }
        if(totalNum<=4){
            showNum=totalNum;
            totalNum=6;
        }
        Integer randomStartIndex= RandomUtils.nextInt(0,totalNum-showNum-1);
        List<TbItem> tbItems = tbItemMapper.randomItem(randomStartIndex,showNum,shopNo);
        List<ItemResultDto> itemResultDtos =new ArrayList<>();
        if(tbItems!=null && tbItems.size()>=1){
            for(TbItem tbItem:tbItems){
                ItemResultDto itemResultDto =convertToDto(tbItem);
                itemResultDtos.add(itemResultDto);
            }
        }
        return itemResultDtos;
    }

    @Override
    public void deleteById(String id) {
        tbItemMapper.deleteByPrimaryKey(Integer.valueOf(id));
    }

    @Override
    public void upOrDown(String itemNo) {
        TbItem tbItem=tbItemMapper.selectByItemNo(itemNo);
        if(StatusCharEnum.VALID.getCode().equals(tbItem.getStatus())){
            tbItem.setStatus(StatusCharEnum.UNVALID.getCode());
        }else {
            tbItem.setStatus(StatusCharEnum.VALID.getCode());
        }
        tbItemMapper.updateByPrimaryKeySelective(tbItem);
    }

    @Override
    public Result<List<ItemResultDto>> findGoodsByStatus(String shopNo, String status) {
        List<TbItem> tbItems = tbItemMapper.selectByStatus(shopNo,status);
        List<ItemResultDto> itemResultDtos =new ArrayList<>();
        if(tbItems!=null && tbItems.size()>=1){
            for(TbItem tbItem:tbItems){
                ItemResultDto itemResultDto =convertToDto(tbItem);
                itemResultDtos.add(itemResultDto);
            }
            return Result.newSuccess(itemResultDtos);
        }else {
            return Result.newError(ResultCode.COMMON_DATA_NOT_EXISTS);
        }
    }

    @Override
    public Result<ItemResultDto> findGoodsByItemNo(String itemNo) {
        TbItem tbItem=tbItemMapper.selectByItemNo(itemNo);
        if(tbItem==null){
            return Result.newError(ResultCode.COMMON_DATA_NOT_EXISTS);
        }
        ItemResultDto itemResultDto =convertToDto(tbItem);
        return Result.newSuccess(itemResultDto);
    }

    @Override
    public void deleteByItemNo(String itemNo) {
        tbItemMapper.deleteByItemNo(itemNo);
    }

    @Override
    public void saveSaleProduct(OpenShopDto openShopDto, SaleProductEnum saleProductEnum) {
        TbItem oldItem=tbItemMapper.selectByItemNo(saleProductEnum.getSaleProductCode());
        if(oldItem!=null){
            return;
        }
        TbItem tbItem = new TbItem();
        String itemNo = saleProductEnum.getSaleProductCode();
        tbItem.setItemNo(itemNo);
        tbItem.setItemTitle(saleProductEnum.getSaleProductName());
        tbItem.setMerNo(openShopDto.getSysMerNo());
        tbItem.setShopNo(openShopDto.getSysShopNo());
        tbItem.setStockType(StockTypeEnum.STOCK_FREE.getCode());
        tbItem.setPrice(saleProductEnum.getSalePrice());
        tbItem.setModiNo(openShopDto.getOperNo());
        tbItem.setModiTime(new Date());
        tbItemMapper.insertSelective(tbItem);
    }

    private ItemResultDto convertToDto(TbItem tbItem) {
        ItemResultDto itemResultDto =new ItemResultDto();
        BeanUtils.copyProperties(tbItem, itemResultDto);
        itemResultDto.setStatusName(ItemStatusEnum.getNameByCode(tbItem.getStatus()));
        ShopInfoDto shopInfoDto=shopInfoService.findByShopNo(tbItem.getShopNo());
        if(shopInfoDto!=null){
            itemResultDto.setShopName(shopInfoDto.getShopName());
            itemResultDto.setMerName(shopInfoDto.getMerName());
        }
        ItemCatResultDto itemCatResultDto1=itemCatService.findByItemCatNo(tbItem.getCatNo1());
        if(itemCatResultDto1!=null){
            itemResultDto.setCatName1(itemCatResultDto1.getCatName());
        }
        ItemCatResultDto itemCatResultDto2=itemCatService.findByItemCatNo(tbItem.getCatNo2());
        if(itemCatResultDto2!=null){
            itemResultDto.setCatName2(itemCatResultDto2.getCatName());
        }
        ItemCatResultDto itemCatResultDto3=itemCatService.findByItemCatNo(tbItem.getCatNo3());
        if(itemCatResultDto3!=null){
            itemResultDto.setCatName3(itemCatResultDto3.getCatName());
        }
        TbItemDetail tbItemDetail=tbItemDetailMapper.selectByItemNo(tbItem.getItemNo());
        if(tbItemDetail!=null){
            itemResultDto.setItemDes(tbItemDetail.getDescription());
        }
        List<TbItemPic> tbItemPics=tbItemPicMapper.selectByItemNo(tbItem.getItemNo());
        if(!CollectionUtils.isEmpty(tbItemPics)){
            List<ItemPicResultDto> itemPicTopResultDtoList=new ArrayList<>();
            List<ItemPicResultDto> itemPicDetailResultDtoList=new ArrayList<>();
            for (TbItemPic tbItemPic:tbItemPics){
                ItemPicResultDto itemPicResultDto=new ItemPicResultDto();
                BeanUtils.copyProperties(tbItemPic,itemPicResultDto);
                itemPicResultDto.setNarrowPicNo(tbItemPic.getNarrowPicUrl());
                itemPicResultDto.setPicNo(tbItemPic.getPicUrl());
                if(StringUtils.isNotEmpty(tbItemPic.getPicUrl()))
                itemPicResultDto.setPicUrl(payDomain+"/common/file/findByNo/"+tbItemPic.getPicUrl());
                if(StringUtils.isNotEmpty(tbItemPic.getNarrowPicUrl()))
                itemPicResultDto.setNarrowPicUrl(payDomain+"/common/file/findByNo/"+tbItemPic.getNarrowPicUrl());
                if(PicLocationEnum.TOP.getCode().equals(itemPicResultDto.getPicLocation())){
                    itemPicTopResultDtoList.add(itemPicResultDto);
                }else {
                    itemPicDetailResultDtoList.add(itemPicResultDto);
                }
            }
            itemResultDto.setItemPicTopResultDtoList(itemPicTopResultDtoList);
            itemResultDto.setItemPicDetailResultDtoList(itemPicDetailResultDtoList);
        }
        List<TbItemSku> tbItemSkus=tbItemSkuMapper.selectByItemNo(tbItem.getItemNo());
        if(tbItemSkus!=null && tbItemSkus.size()>=1){
            List<ItemSkuResultDto> itemSkuResultDtos=new ArrayList<>();
            for(TbItemSku tbItemSku:tbItemSkus){
                ItemSkuResultDto itemSkuResultDto=new ItemSkuResultDto();
                BeanUtils.copyProperties(tbItemSku,itemSkuResultDto);
                itemSkuResultDto.setProfitTypeName(ProfitTypeEnum.getNameByCode(tbItemSku.getProfitType()));
                itemSkuResultDto.setNarrowPicNo(tbItemSku.getNarrowPicUrl());
                itemSkuResultDto.setPicNo(tbItemSku.getPicUrl());
                if(tbItemSku.getCost()!=null)
                    itemSkuResultDto.setCostPrice(tbItemSku.getCost());
                if(tbItemSku.getSalePrice()!=null)
                    itemSkuResultDto.setSalePrice(tbItemSku.getSalePrice());
                if(tbItemSku.getPrice()!=null)
                     itemSkuResultDto.setPrice(tbItemSku.getPrice());
                if(tbItemSku.getStockNum()!=null)
                itemSkuResultDto.setStockNum(tbItemSku.getStockNum().toString());
                if(StringUtils.isNotEmpty(tbItemSku.getPicUrl()))
                itemSkuResultDto.setPicUrl(payDomain+"/common/file/findByNo/"+tbItemSku.getPicUrl());
                if(StringUtils.isNotEmpty(tbItemSku.getNarrowPicUrl()))
                itemSkuResultDto.setNarrowPicUrl(payDomain+"/common/file/findByNo/"+tbItemSku.getNarrowPicUrl());
                itemResultDto.setPicUrl(itemSkuResultDto.getPicUrl());
                itemResultDto.setNarrowPicUrl(itemSkuResultDto.getNarrowPicUrl());
                itemResultDto.setPrice(tbItemSku.getPrice());
                itemResultDto.setStockNum(tbItemSku.getStockNum());
                //团长单件利润
                BigDecimal scoreAmt=tbItemSku.getScorePercent().divide(new BigDecimal("100")).multiply(tbItemSku.getPrice());
                itemSkuResultDto.setScoreAmt(scoreAmt);
                itemSkuResultDtos.add(itemSkuResultDto);
            }
            itemResultDto.setItemSkuResultDtos(itemSkuResultDtos);
        }
        return itemResultDto;
    }
}
